package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.dto.NursingProjectPlanDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.entity.NursingProjectPlan;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class NursingProjectServiceimpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 分页查询护理项目
     *
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> PageNursing(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page page = nursingProjectMapper.PageNursing(name, status);
        return PageResponse.of(page, NursingProjectVo.class);
    }
    /**
     * 新增护理
     * @param nursingProjectDto
     */
    @Override
    public void addNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto, nursingProject);

        nursingProject.setCreateTime(LocalDateTime.now());
        nursingProjectMapper.addNursingProject(nursingProject);
    }

    /**
     * 根据id查询护理
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getNursing(Long id) {
        return nursingProjectMapper.getNursing(id);
    }

    /**
     * 修改护理项目
     * @param nursingProjectDto
     */
    @Override
    public void updateNursing(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto, nursingProject);
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProject.setUpdateBy(1l);
        nursingProjectMapper.updateNursingProject(nursingProject);
    }

    /**
     * 删除护理项目
     * @param id
     */
    @Override
    public void deleteNursing(Long id) {
        nursingProjectMapper.deleteNursing(id);
    }

    /**
     * 查询所有护理项目
     * @return
     */
    @Override
    public Object getAllNursingProject() {
       List<NursingProjectVo> list = nursingProjectMapper.getAllNursingProject();
       list.stream().map(nursingProjectVo -> {
           NursingProjectVo nursingProjectVo1 = new NursingProjectVo();
           BeanUtils.copyProperties(nursingProjectVo, nursingProjectVo1);
           return nursingProjectVo1;
       }).collect(Collectors.toList());
       return list;
    }

    /**
     * 启用/禁用护理项目
     * @param id
     * @param status
     */
    @Override
    public void modifyState(Long id, Integer status) {
        nursingProjectMapper.modifyState(id, status);
    }


}
